package com.jarvan.controller;

import com.jarvan.enums.ResultEnum;
import com.jarvan.exception.TrainException;
import com.jarvan.model.Station;
import com.jarvan.service.impl.StationServiceImpl;
import com.jarvan.utils.ResultVoUtil;
import com.jarvan.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "站点api")
@RestController
@RequestMapping("/station")
@Slf4j
public class StationController {
    @Autowired
    private StationServiceImpl stationService;

//    @Autowired
//    private ResultVoUtil<T> resultVoUtil;
    @ApiOperation(value = "查询火车站")
    @GetMapping("/getStationByName")
    public ResultVo<Station> findByName(@RequestParam("stationName") String stationName){
        if (stationName.isEmpty()){
            log.error("[站点查询] -- 站点不存在 stationName={}", stationName);
            throw new TrainException(ResultEnum.PARAM_ERROR.getCode(),
                    ResultEnum.PARAM_ERROR.getMessage());
        }
        Station station = stationService.findbyStationName(stationName);
        return ResultVoUtil.success(station);
    }
}
